// components/input.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    url: {
      type: String,
      value: ''
    },
    placeholder: {
      type: String,
      value: ''
    },
    maxlength: {
      type: Number,
      value: ''
    },
    type: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isClearShow: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clearTap() {
      this.setData({
        isClearShow: false,
        inputValue: ''
      });
    },
    inputListener(e) {
      let value = e.detail.value;
      let cursor = e.detail.cursor;
      if (value === null || value === undefined || value.length === 0) {
        this.setData({
          isClearShow: false
        });
      } else {
        this.setData({
          isClearShow: true
        });
      }
      let detail = {
        value: value,
        cursor: cursor
      };
      this.triggerEvent('cminput', detail);
    },
    inputConfirm(e) {
      let value = e.detail.value;
      let detail = {
        value: value
      };
      this.triggerEvent('cmconfirm', detail);
    },
    inputBlur(e) {
      let value = e.detail.value;
      let detail = {
        value: value
      };
      this.triggerEvent('cmblur', detail);
    }
  }
});
